#ifndef __MaterialH__
#define __MaterialH__

#include "Vectors.h"
#include "Hit.h"
#include "Ray.h"
#include "image.h"

class Material
{
public:
	Material(Vec3f ambientColor,Vec3f diffuseColr, Vec3f transparentColor, 
		Vec3f reflectiveColor, float indexOfRefraction);
	
	virtual Vec3f Shade(const Ray &ray, const Hit &hit, const Vec3f &dirToLight,
		const Vec3f &lightColor) const = 0;
	Vec3f getAmbientColor()const{return m_ambientColor;}
	Vec3f getDiffuseColor()const{return m_diffuseColor;}
	Vec3f getTransparentColor()const{return m_transparentColor;}
	Vec3f getReflectiveColor()const {return m_reflectiveColor;}
	float getIndexOfRefraction()const{return m_indexOfRefraction;}
	bool  isMirror() {return !m_reflectiveColor.isZero();}
	bool  isTransparent() {return !m_transparentColor.isZero();} 
	virtual bool hasTexture() {return false;}
	void debugMessage();
protected:
	Vec3f m_ambientColor;
	Vec3f m_diffuseColor;
	Vec3f m_transparentColor;
	Vec3f m_reflectiveColor;
	float m_indexOfRefraction;
};

class PhongMaterial : public Material
{
public:
	PhongMaterial(Vec3f ambientColor,Vec3f diffuseColor, Vec3f specularColor, float exponent,
		Vec3f transparentColor, Vec3f reflectiveColor, float indexOfRefraction);
	virtual Vec3f Shade(const Ray &ray, const Hit &hit, const Vec3f &dirToLight,
		const Vec3f &lightColor) const;
protected:
	Vec3f m_specularColor;
	float m_exponent;
};

class TextureMaterial : public PhongMaterial
{
public:
	TextureMaterial(Vec3f ambientColor,Vec3f diffuseColor,Vec3f specularColor,float exponent,
		Vec3f transparentColor,Vec3f reflectiveColor,float indexOfRefraction,
		const char *fileName):PhongMaterial(ambientColor,diffuseColor,specularColor,
		exponent,transparentColor,reflectiveColor,indexOfRefraction){
		m_pImage = Image::LoadTGA(fileName);
	}
	Vec3f getTextureColor(float x,float y){
		return m_pImage->GetLinearPixel(x,1.f-y);
	}
	virtual bool hasTexture() { return true; }
private:
	Image *m_pImage;
};

#endif